﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace Tool.Resources
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("***********This is the resources Generator********");
            Console.WriteLine("                                  Made By Kingmoon\n\n");
            string localpath = AppDomain.CurrentDomain.BaseDirectory;
            string resgenpath = Path.Combine(localpath + "resgen.exe");
            string stringrespath = Path.Combine(localpath, "StringResources");
            if (!File.Exists(resgenpath))
            {
                Console.WriteLine("resgen.exe lost. Generate Resources Failed");
                Console.ReadKey();
                return;
            }

            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe ";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();

            Console.WriteLine("Generate The String Resources.......");
            foreach (string i in Directory.GetFiles(stringrespath))
            {
                if (i.IndexOf("AgnesStringRes") != -1
                    && i.LastIndexOf(".resx") == i.Length-5)
                {
                    string outname = i.Replace(".resx", ".resources");
                    string inpath = Path.Combine(localpath, "StringResources", i);
                    string outpath = Path.Combine(localpath, "StringResources", outname);
                    p.StandardInput.WriteLine(resgenpath + " \""
                        + inpath +"\" \""+outpath+"\"");
                    
                }
            }

            p.StandardInput.WriteLine("exit");
            
            Console.WriteLine(p.StandardOutput.ReadToEnd());
            p.Close();
            Console.ReadKey();
        }
    }
}
